<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\common\model;

use app\common\model\Apply;

class Note
{
    public $_type = [
        0 => '审核未通过',
        1 => '参与活动',
    ];

    public static function sendApplyCheck($phone)
    {
        $content="【美育儿】您报名参加的美育儿投票比赛审核未通过。";//要发送的短信内容
        return static::send($phone, $content);
    }

    public static function applySuccess($applyId)
    {
        $apply = Apply::get($applyId);
        $content="【美育儿】". $apply->user->nickname ."，您已成功报名『". $apply->activity->title ."』活动，不妨在个人中心，进行充值、答谢设置，为宝宝拉票，效果会更好哟！";
        return static::send($apply['mobile'], $content, 1);
    }

    public static function send($phone, $content, $type = 0)
    {
        $statusStr = [
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        ];

        $nodeConfig = config('send_node');
        $sendurl = $nodeConfig['smsapi'] . "sms?u=". $nodeConfig['user'] ."&p=".md5($nodeConfig['pass'])."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl);
        return [
            'code' => $result,
            'str' => $statusStr[$result]
        ];
    }
}
